package com.jackrain.nea.common;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.ReferenceUtil;
import com.jackrain.nea.web.QueryCmd;

import java.util.HashMap;

/**
 * @author wuwenxue
 * @date 2018/07/04
 **/
public class QueryCpUtil {

    @Reference(group = "cp",version = "2")
    private QueryCmd queryCmd;

    /**
     * 跨库查询
     *
     * @param tableName 表名
     * @param field     字段
     * @param whereJson 条件
     * @return hashmap
     */
    public static HashMap queryCP(String tableName, String field, JSONObject whereJson) {
        HashMap cpHashMap = new HashMap(16);
        cpHashMap.put("type", HashMap.class);
        cpHashMap.put("tableName", tableName);
        cpHashMap.put("fields", field);
        cpHashMap.put("whereKeys", whereJson);

        Object o = ReferenceUtil.refer(ApplicationContextHandle.getApplicationContext(),
                "com.jackrain.nea.web.QueryCmd", "cp", "2");
        HashMap result = (HashMap)((QueryCmd) o).queryTable(cpHashMap);

        JSONObject cpJson = new JSONObject(result);

        return result;
    }



}
